<?php

namespace App\Http\Middleware\Admin;

use App\Models\Category;
use App\Models\Communities;
use App\Models\District;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\View;

class Init
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @param  string|null $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        //判断权限
        $request_method = $_SERVER['REQUEST_METHOD'];
        $user = Auth::user();
        if (!$user->isAdmin()) {
            if ($request_method == 'POST') {
                abort(422,'您没有权限操作后台');
            } else {
                return redirect('/');
            }
        }
        return $next($request);
    }
}
